import App from './App'
// 全局路由跳转拦截器
const loginRoutePath = '/pages/login/index';
['redirectTo', 'navigateTo', 'switchTab', 'reLaunch'].forEach(apiName => {
	uni.addInterceptor(apiName, {
		invoke: (options, completeCallback) => {
			const token = uni.getStorageSync('token');
			const targetPageRoute = options.url || options.deltaUrl;
			if (targetPageRoute === loginRoutePath) {
				// 放行登录页的跳转
				return true;
			} else if (!token) {
				// 关闭当前页面并跳转到登录页
				uni.reLaunch({
					url: loginRoutePath
				});
				// 阻止原跳转
				return false;
			} else {
				// 登录有效，允许跳转
				return true;
			}
		}
	});
});

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import {
	setPinia
} from './store';
export function createApp() {
	const app = createSSRApp(App)
	setPinia(app)
	return {
		app
	}
}
// #endif